﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VietImage.Models;
using VietImage.Roles;

namespace VietImage.Controllers
{
    public class GetListController : Controller
    {
        //
        // GET: /GetList/

        public static int GetLanguage(HttpRequest req, HttpResponse res)
        {
            HttpCookie languageCookie = null;
            if (languageCookie == null)
            {
                languageCookie = new HttpCookie("Language");
                languageCookie.Value = "2";
            }
            languageCookie.Expires = DateTime.Now.AddMonths(1);
            //Response.SetCookie(languageCookie);
            return int.Parse(languageCookie.Value);
        }

        public ActionResult Index()
        {
            return View();
        }

        public String SubCategory(int cat)
        {
            int lang = 2;
            List<Category> lst = Category.GetListAvailableSubCategories(cat);
            String result = "";
            if (lst != null)
            {
                foreach (Category c in lst)
                {
                    result += "<p id=\"SubCat" + c.ID + "\">" + c.GetDetail(lang).Name + "</p>\n";
                }
            }
            return result;
        }

        public String MyLightboxes(int id = 0)
        {
            String result = "";
            RegisteredUserRole _role = (RegisteredUserRole)Session["Role"];
            if (_role != null)
            {
                List<Lightbox> lst = Lightbox.GetListAvailableOfUser(_role.UserInfo.ID);
                foreach (Lightbox lb in lst)
                {
                    result += "<option value=\"" + lb.ID + "\" " + ((lb.ID == id) ? "selected" : "") + ">" + lb.Name + "</option>";
                }
            }
            return result;
        }

        public String CitiesOfCountry(int id = 0, int sel = -1)
        {
            String result = "";
            List<City> CityList = City.GetList(id);
            if (CityList != null)
            {
                foreach (City c in CityList)
                {
                    result += "<div class=\"combobox_item\" value=\"" + c.ID + "\" " + ((c.ID == sel) ? "selected" : "") + ">" + c.Name + "</div>";
                }
            }
            return result;
        }

    }
}
